﻿using Tree;

string[] operations = { "+", "-", "S", "N" };
string LOG_PATH = "C:\\Users\\antrelax\\source\\repos\\AVL-Tree\\AVL-Tree\\logs\\";
string CONSOLE_TEXT = "Input operation (\"+\" - add, \"-\" - delete, \"T\" - test, \"L\" - test from log, \"S\" - show, \"N\" - exit): ";
binTree myTree = new binTree();
string inputOper = "S";


void makeAddOpToTree(binTree tree)
{
    Console.Write("Input some value to add in Tree: ");
    int value = Convert.ToInt16(Console.ReadLine());
    tree.add(value);
    myTree = myTree.getRoot();
}

void makeDelOpFromTree(binTree tree)
{
    Console.Write("Input some value to delete it from Tree: ");
    int value = Convert.ToInt16(Console.ReadLine());
    tree.remove(value);
    myTree = myTree.getRoot();
}

void showTree()
{
    myTree.showLikeLine();
    Console.Write("\nInput some button to continue... ");
    Console.ReadKey();
}

void startTest(int[] testNumbs = null)
{
    if (testNumbs == null)
    {
        testNumbs = new int[10];
        Random rand = new Random();

        for (int i = 0; i < 10; i++)
        {
            testNumbs[i] = rand.Next(100);
            Console.Write(testNumbs[i]);
            Console.Write(' ');
        }
    }

    for (int i = 0; i < 10; i++)
    {
        Console.WriteLine();
        myTree.add(testNumbs[i]);
        myTree = myTree.getRoot();
        myTree.showLikeLine();
    }
    string randNumbsLog = "";
    for (int i = 0; i < 10; i++) randNumbsLog += testNumbs[i].ToString() + ", ";
    File.WriteAllText(LOG_PATH + "log(" + DateTime.Now.ToString().Replace(":", "-") + ").txt", randNumbsLog);
    Console.ReadKey();
}

void startLogTest()
{
    int[] numbs = { 2, 18, 86, 45, 46, 39, 63, 63, 50, 10}; //Must get numbers from log file in LOG_PATH
    startTest(numbs);
}

while (inputOper != "N")
{
    Console.Write(CONSOLE_TEXT);
    inputOper = Console.ReadLine().ToUpper();

    switch (inputOper)
    {
        case "+":
            makeAddOpToTree(myTree);
            break;
        case "-":
            makeDelOpFromTree(myTree);
            break;
        case "S":
            showTree();
            break;
        case "T":
            startTest();
            break;
        case "L":
            startLogTest();
            break;
        default:
            break;
    }
    Console.Clear();
}